package com.winchain.chainbill.risk.biz.rate.controller;

import com.shell.bee.base.annotation.Logging;
import com.shell.bee.entity.mvc.RetMsg;
import com.shell.bee.mvc.controller.BaseController;
import com.shell.bee.persistence.model.PageLimit;
import com.shell.bee.persistence.model.PageModel;
import com.shell.framework.utils.CommonDataUtil;
import com.shell.framework.utils.ParameterHelper;
import com.shell.governor.modules.vo.ParameterVo;
import com.winchain.chainbill.basic.cus.vo.BasCustomerVo;
import com.winchain.chainbill.risk.base.service.RmIntRateService;
import com.winchain.chainbill.risk.biz.rate.vo.RateVo;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class RateController extends BaseController {
	@Autowired
	private RmIntRateService rmIntRateService;

	@RequestMapping
	@ResponseBody
	@Logging(module = "��������", methods = "������������")
	public List<BasCustomerVo> findCustomerRateForVar(PageLimit limit, String grpId, String searchValue) {
		String[] tagCodes = { "FOCAL_CO", "MEMBER", "SUPPLIER" };
		String[] bizCodes = { "KDYW" };
		PageModel<BasCustomerVo> result = (PageModel) this.rmIntRateService.findCustomerRateForGrp(limit, grpId,
				CommonDataUtil.getCurEntId(), tagCodes, searchValue, "1", null, bizCodes);
		ParameterVo sndNeedInterest = ParameterHelper.getCommonParameter("SND_NEED_INTEREST");
		result.getExtend().put("isShowsndRate", Boolean.valueOf(sndNeedInterest.getParmValue().equals("1")));
		return result;
	}

	@RequestMapping
	@ResponseBody
	@Logging(module = "��������", methods = "��������������")
	public List<BasCustomerVo> findCustomerRateForEntVar(PageLimit limit, String grpId, String entId,
			String searchValue) {
		String[] tagCodes = { "SUPPLIER" };
		PageModel<BasCustomerVo> result = (PageModel) this.rmIntRateService.findCustomerRateForGrp(limit, grpId, entId,
				tagCodes, searchValue, "2", null, null);
		ParameterVo sndNeedInterest = ParameterHelper.getCommonParameter("SND_NEED_INTEREST");
		result.getExtend().put("isShowsndRate", Boolean.valueOf(sndNeedInterest.getParmValue().equals("1")));
		return result;
	}

	@RequestMapping
	@ResponseBody
	@Logging(module = "��������", methods = "����������������")
	public List<RateVo> findRateForEnt(String rateBizType, String grpId, String cusId, String finId) {
		return this.rmIntRateService.findRateForEnt(rateBizType, grpId, cusId, finId);
	}

	@RequestMapping
	@ResponseBody
	@Logging(module = "��������", methods = "����������������")
	public RetMsg updateRate(RateVo rateVo) {
		this.rmIntRateService.updateRate(rateVo);
		return initRetMsg("success", "��������");
	}

	@RequestMapping
	@ResponseBody
	@Logging(module = "��������", methods = "��������������")
	public RateVo findRateByCode(String rateBizType, String rateCode, String grpId, String cusId, String finId) {
		return this.rmIntRateService.findRateByCode(rateBizType, rateCode, grpId, cusId, finId);
	}

	@RequestMapping
	@ResponseBody
	@Logging(module = "��������", methods = "������������")
	public List<BasCustomerVo> findCustomerDctRateForEnt(PageLimit limit, String grpId, String entId,
			String searchValue) {
		String[] tagCodes = { "FOCAL_CO", "MEMBER", "SUPPLIER" };
		String[] bizCodes = { "KDYW" };
		PageModel<BasCustomerVo> result = (PageModel) this.rmIntRateService.findCustomerRateForGrp(limit, grpId, entId,
				tagCodes, searchValue, "6", null, bizCodes);
		return result;
	}

	@RequestMapping
	@ResponseBody
	@Logging(module = "��������", methods = "����������������")
	public List<BasCustomerVo> findFocalRateForEnt(PageLimit limit, String grpId, String entId, String searchValue,
			String bizType) {
		String[] tagCodes = { "FOCAL_CO", "MEMBER", "SUPPLIER" };
		String[] bizCodes = { "KDYW" };
		PageModel<BasCustomerVo> result = (PageModel) this.rmIntRateService.findCustomerRateForGrp(limit, grpId, entId,
				tagCodes, searchValue, bizType, null, bizCodes);
		return result;
	}
}
